package bjut.zrpc.core.optimization.enums;


import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Author: zhuzhiming
 * @Date: 2022/6/24 0:28
 */
@AllArgsConstructor
@Getter
public enum ZRpcCompressEnum {

    GZIP((byte) 0x01, "gzip"),
    SNAPPY((byte)0x02,"snappy");

    private final byte type;
    private final String compressName;

    public static String getCompressName(byte type) {
        for (ZRpcCompressEnum value : ZRpcCompressEnum.values()) {
            if (value.getType() == type) {
                return value.getCompressName();
            }
        }
        return null;
    }

    public static byte getCompressType(String compressName) {
        for (ZRpcCompressEnum value : ZRpcCompressEnum.values()) {
            if (value.getCompressName().equals(compressName)) {
                return value.getType();
            }
        }
        return (byte) 0x01;
    }

}
